package com.jp.study.model.page;

import java.util.Iterator;
import java.util.List;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("分页对象")
public class JPPageImpl<T> implements Page<T>{
	
	@ApiModelProperty("分页分出的数据")
	private List<T> data;
	@ApiModelProperty("查出的总记录数")
	private long elementsSum;
	@JsonIgnore
	private Page<T> page;
	
	public JPPageImpl(Page<T> page) {
		this.page=page;
		this.data=page.getContent();
		this.elementsSum=page.getTotalElements();
	}
	public JPPageImpl(List<T> data,long elementSum) {
		this.data=data;
		this.elementsSum=elementSum;
	}
	
	public List<T> getData() {
		return data;
	}
	public void setData(List<T> data) {
		this.data = data;
	}
	public long getElementsSum() {
		return elementsSum;
	}
	public void setElementsSum(long elementsSum) {
		this.elementsSum = elementsSum;
	}

	@Override
	@JsonIgnore
	public int getNumber() {
		return page.getNumber();
	}
	@Override
	@JsonIgnore
	public int getSize() {
		return page.getSize();
	}
	@Override
	@JsonIgnore
	public int getNumberOfElements() {
		return page.getNumberOfElements();
	}
	@Override
	@JsonIgnore
	public List<T> getContent() {
		return data;
	}
	@Override
	@JsonIgnore
	public boolean hasContent() {
		return data!=null&&(!data.isEmpty());
	}
	@Override
	@JsonIgnore
	public Sort getSort() {
		return page.getSort();
	}
	@Override
	@JsonIgnore
	public boolean isFirst() {
		return page.isFirst();
	}
	@Override
	@JsonIgnore
	public boolean isLast() {
		return page.isLast();
	}
	@Override
	@JsonIgnore
	public boolean hasNext() {
		return page.hasNext();
	}
	@Override
	@JsonIgnore
	public boolean hasPrevious() {
		return page.hasPrevious();
	}
	@Override
	@JsonIgnore
	public Pageable nextPageable() {
		return page.nextPageable();
	}
	@Override
	@JsonIgnore
	public Pageable previousPageable() {
		return page.previousPageable();
	}
	@Override
	@JsonIgnore
	public Iterator<T> iterator() {
		return page.iterator();
	}
	@Override
	@JsonIgnore
	public int getTotalPages() {
		return page.getTotalPages();
	}
	@Override
	@JsonIgnore
	public long getTotalElements() {
		return page.getTotalElements();
	}
	@Override
	@JsonIgnore
	public <S> Page<S> map(Converter<? super T, ? extends S> converter) {
		return page.map(converter);
	}
}

